from data_source import InsuranceDataSource
from metrics_calculator import InsuranceMetricsCalculator


def main():
    # 1. 加载数据（数据源层）
    data_source = InsuranceDataSource()
    data = data_source.load_sample_data()  # 加载示例数据
    print("=== 加载的数据 ===")
    print(data[["period", "original_premium", "retained_premium"]])  # 打印部分数据

    # 2. 初始化指标计算器（计算层）
    calculator = InsuranceMetricsCalculator(data)

    # 3. 计算并输出指标（以2024Q1为报告期，2023Q1为基期为例）
    report_period = "2024Q1"
    base_period = "2023Q1"
    print(f"\n=== {report_period} 指标计算结果（基期：{base_period}） ===")

    # 增长类指标
    original_growth = calculator.get_original_premium_growth_rate(report_period, base_period)
    print(f"1. 原保费收入增长率：{original_growth:.2f}%")

    retained_growth = calculator.get_retained_premium_growth_rate(report_period, base_period)
    print(f"2. 自留保费增长率：{retained_growth:.2f}%")

    # 市场份额类指标
    market_share = calculator.get_original_market_share(report_period)
    print(f"3. 原保费市场份额：{market_share:.2f}%")

    incremental_share = calculator.get_incremental_market_share(report_period, base_period)
    print(f"4. 原保费增量市场份额：{incremental_share:.2f}%")

    dev_coeff = calculator.get_development_coefficient(report_period, base_period)
    print(f"5. 发展系数：{dev_coeff:.2f}")

    # 其他指标
    first_year_ratio = calculator.get_first_year_premium_ratio(report_period)
    print(f"6. 首年保费与保费收入比：{first_year_ratio:.2f}%")

    renewal_rate = calculator.get_13_month_renewal_rate(report_period)
    print(f"7. 13个月续保率：{renewal_rate:.2f}%")

    avg_agent_premium = calculator.get_agent_average_premium(report_period)
    print(f"8. 人均保费：{avg_agent_premium:.2f} 万元/人")

    std_growth = calculator.get_standard_premium_growth_rate(report_period, base_period)
    print(f"9. 标准保费增长率：{std_growth:.2f}%")

    retained_equity_ratio = calculator.get_retained_premium_to_equity_ratio(report_period)
    print(f"10. 自留保费占净资产比：{retained_equity_ratio:.2f}%")


if __name__ == "__main__":
    main()